﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Forms;
using System.Drawing;

using EzDesk.DesktopClient.Event;
using EzDesk.EventAggregation;
using EzDesk.Generic.WPF;
using EzDesk.DesktopClient;
using EzDesk.DesktopClient.ViewContract;
using EzDesk.DesktopClient.ViewModel;


namespace EzDesk.DesktopClient.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class ShellView : WindowExtenBase, IShellView
    {

        public object ViewModel
        {
            get
            {
                return this.DataContext;
            }
            set
            {
                this.DataContext = value;
            }
        }

        WindowState ws;
        WindowState wsl;
        NotifyIcon notifyIcon;
        int count = 0;

        public ShellView()
        {
            InitializeComponent();
            InitView();
            InitEvent();
            //icon();
            wsl = WindowState;
        }

        public void InitView()
        {
            LoginViewModel loginViewModel = new LoginViewModel();
            MainContent.Content = loginViewModel.View;

            TopPanelViewModel topViewModel = new TopPanelViewModel();
            TopContent.Content = topViewModel.View;

        }
        public void InitEvent()
        {
            LoginEvent.Instance.Subscribe(arg =>
                {
                    if (arg.IsSuccess)
                    {
                        MainContent.Content = new ContentTabViewModel().View;
                        SelfInfoContent.Content =new SelfInfoViewModel().View;
                    }
                }
                );
            LogoutEvent.Instance.Subscribe(arg => 
            {
                MainContent.Content = new LoginViewModel().View;
            });

        }

        private void OnNotifyIconDoubleClick(object sender, EventArgs e)
        {
            this.Show();
            this.ShowInTaskbar = true;
            WindowState = wsl;
            this.Topmost = true;
        }
        private void Window_StateChanged(object sender, EventArgs e)
        {
            ws = WindowState;
            if (ws == WindowState.Minimized)
            {
                this.ShowInTaskbar = false;
                Hide();
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.ShowInTaskbar = false;
            this.Hide();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            LogoutEvent.Instance.Publish(new LogoutArgs());
            IMClient.CurrentClient.Shutdown();   
        }

    }
}
